<script setup lang="ts">
import type {KeyValue} from "~/types";
import {ElOption, ElSelect} from "element-plus";
const form=reactive({
  limit:10,
  page:1,
});
definePageMeta({
  layout:'admin',
  title:'模板列表',
});
const {data:list,refresh}=await useServerGet('/west/getTemplateList',form)
const deleteTemplate=async (id:number)=>{
  ElMessageBox.confirm('确定删除该模板吗？','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning',
    center:true,
  }).then(async ()=>{
    const {code}=await usePost('/west/deleteTemplate',{id})
    if(code==200){
      ElMessage.success('删除成功');
      refresh?.();
    }
  })
}
const realName=async (row:any)=>{
  ElMessageBox.confirm('确定认证该模板吗？','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning',
    center:true,
  }).then(async ()=>{
    const {code}=await usePost('/west/realNameForTemplate',{id:row.id,certification_id:row.certification_id})
    if(code==200){
      ElMessage.success('认证成功');
      refresh?.();
    }
  })
}
const setDefault=async (row:any)=>{
  ElMessageBox.confirm('确定设定该模板为默认模版吗？','提示',{
    confirmButtonText:'确定',
    cancelButtonText:'取消',
    type:'warning',
    center:true,
  }).then(async ()=>{
    const {code}=await usePost('/west/setDefault',{id:row.id})
    if(code==200){
      ElMessage.success('设置成功');
      refresh?.();
    }
  })
}

</script>

<template>
  <div>
    <AuthenText>
<pre>
关于设置默认模板的说明：
1、每个账户只能设置一个默认模板，设置前，模板必须先通过审核。
2、默认模板作用：您的账户注册域名，得标域名，转入域名，PUSH域名，购买域名，等等操作，系统会将域名Whois信息设置为默认模板的信息。
3、如果账户没有设置默认模板，您的账户域名解析权限将被暂时关闭。</pre>
    </AuthenText>
    <el-card class="flex-1">
      <el-button class="my-3" type="primary"><NuxtLink to="/admin/domain/templateAdd">添加模版</NuxtLink></el-button>
      <el-table
        :data="list.data.data"
        style="width: 100%"
        align="center"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
      >
        <el-table-column label="编号">
          <template #default="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="姓名">
          <template #default="scope">{{ scope.row.fullname }}</template>
        </el-table-column>
        <el-table-column label="类型">
          <template #default="scope">{{ scope.row.c_regtype=='I'?'个人':'企业' }}</template>
        </el-table-column>
        <el-table-column label="省市区">
          <template #default="scope">{{ scope.row.c_st_m }}{{ scope.row.c_ct_m }}{{ scope.row.c_dt_m }}</template>
        </el-table-column>
        <el-table-column label="详细地址">
          <template #default="scope">{{ scope.row.c_adr_m }}</template>
        </el-table-column>
        <el-table-column label="邮编">
          <template #default="scope">{{ scope.row.c_pc }}</template>
        </el-table-column>
        <el-table-column label="电话">
          <template #default="scope">{{ scope.row.c_ph }}</template>
        </el-table-column>
        <el-table-column label="邮箱">
          <template #default="scope">{{ scope.row.c_em }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <div>
              <el-dropdown>
                <el-button>
                  更多操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu >
                    <el-dropdown-item @click="deleteTemplate(scope.row.id)">删除</el-dropdown-item>
                    <!--                  push-->
                    <el-dropdown-item @click="setDefault(scope.row)">设置默认模版</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
            <el-button type="text" size="small" @click="realName(scope.row)">认证</el-button>
          </template>
        </el-table-column>
      </el-table>

      <MyPage v-model:page="form.page" v-model:perpage="form.limit" v-model:total="list.data.total"></MyPage>
    </el-card>
  </div>

</template>

<style scoped lang="scss">
.border-right{
  &:last-child{
    border-right: none;
  }
  padding-left: 20px;
  border-right: 1px solid var(--el-border-color);
}
</style>